"""
    @author    Thomas Lehmann
    @file      green-yellow-red-limit.py
    @language  Please use python >= 3.2

    @note Using the tool against itself should never throw any warning or error!
    @note I don't use TAB's and indentation is 4.
    @note I'm using the documentation tool 'epydoc' (http://epydoc.sourceforge.net/)
          for generating HTML documentation of this.
"""

class GreenYellowRedLimit:
    """ this class handles three ranges: green, yellow and red.
        <ul>
            <li><b>green</b>:  indicates that a value is valid
            <li><b>yellow</b>: indicates that the value is accepted but not ok.
                               A warning message will be generated.
            <li><b>red</b>:    indicates an unacceptable state.
                               An error message will be generated.
        </ul>
    """
    def __init__(self, maxGreen, maxYellow, message):
        """ stores limit information
            @param maxGreen
                        is the maximum value which is valid
            @param maxYellow
                        is the maximum value for warning. Is the value more
                        then it is an error.
            @param message
                        is the message printed when the limit is at least
                        more than maxGreen.
        """
        self.maxGreen  = maxGreen
        self.maxYellow = maxYellow
        self.message   = message

    def isGreenFor(self, value):
        """ Checking for a value to be in a valid range.
            @param  value
                        that value to check to be in green state (valid)
            @return true when the given value is valid.
        """
        return value <= self.maxGreen

    def isRedFor(self, value):
        """ Checking for a value to be in an invalid range.
            @param  value
                        that value to check to be in red state (invalid)
            @return true when the given value is invalid.
        """
        return value > self.maxYellow

    def getMessage(self, value):
        """ generates printable warning/error message
            @param value
                    that value that raises the warning/error

            @note It is assumed that the "not green" status has
                  been checked before.
        """
        prompt = "warning: "
        if value > self.maxYellow: prompt = "error: "

        return prompt + self.message + ", value is %d" % value +\
               " (green<=%d,yellow>=%d,red>=%d)" %\
               (self.maxGreen, self.maxGreen+1, self.maxYellow+1)
